﻿using System;
using System.Threading.Tasks;

namespace NMbsDuplex.TCPServerX.Net.TencentOpenAPI
{
    using System.Net.Http;

    // 微信企业官网 domain
    public class OpenAPIDeploy : IDevelopStart
    {
        public const string workQy = "https://work.weixin.qq.com/";
        public string _corpCache;

        #region 腾讯开发平台自动化脚本 - 实现接口 IDevelopStart
        public string MyCorpID
        {
            get
            {
                return _corpCache;
            }
        }
        public string GetAccessToken(string corpID, string secret)
        {
            if (!string.IsNullOrEmpty(corpID) && !string.IsNullOrWhiteSpace(corpID))
            {
                _corpCache = corpID;
                var oriUrl = @"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRECT";
                oriUrl = oriUrl.Replace("=ID", "=" + MyCorpID);
                oriUrl = oriUrl.Replace("SECRECT", secret);
                string access_token = string.Empty;
                access_token = AsyncPool.AsyncTool.CurlV2(oriUrl);
                Console.WriteLine("腾讯企业API返回 ---> " + access_token);
                return access_token;
            }
            return "字符串corpID参数无效|异步开发模型错误 [异步请求没有成功]";
        }
        #endregion
    }
}